# from typing import Optional
#
# from fastapi import APIRouter, Form, Query
#
# from app.api.deps import DbDependency
# from app.crud import goods as goods_crud
# from app.crud import goods_image as goods_image_crud
# from app.crud import goods_sku as goods_sku_crud
# from app.schemas.goods import GoodsList
# from app.utils.response import pageInfo, success_response
#
# router = APIRouter()
#
#
# @router.post("/detail", summary="商品详情页")
# async def detail(db: DbDependency,
#                  goods_id: int = Form(..., description="商品id")):
#     goods = goods_crud.get_user_by_id(db, goods_id)
#     goods_detail = GoodsList.model_construct(**goods.__dict__)
#
#     images = goods_image_crud.get_goods_images(
#         db=db, goods_id=goods_detail.goods_id)
#     if  images:
#         goods_detail.image = images
#     goods_detail.skuList = goods_sku_crud.get_goods_sku(db=db, goods_id=goods_detail.goods_id)
#     return success_response(data=goods_detail, message="短信发送成功")
#
#
# @router.get("/list", summary="商品搜索")
# async def query_goods_list(
#         db: DbDependency,
#         sortType: str = Query(all, description="all-按综合搜索(默认)，sales-按销量搜索，price-按价格搜索"),
#         sortPrice: str = Query(0, description="0-价格从低到高,1-价格从高到低"),
#         categoryId: Optional[int] = Query(None, description="分类ID"),
#         goodsName: Optional[str] = Query(None, description="商品名称，模糊匹配"),
#         pageNo: Optional[int] = Query(1, description="页码"),
#         pageSize: Optional[int] = Query(10, description="每页条数"),
#
# ):
#     total = goods_crud.goods_list_count(db, sortType, sortPrice, categoryId, goodsName)
#     goods_list = goods_crud.goods_list(db, sortType, sortPrice, categoryId, goodsName, pageNo, pageSize)
#     goodss = [GoodsList.model_construct(**g.__dict__) for g in goods_list]
#     for goods in goodss:
#         goods.image = goods_image_crud.get_goods_images(
#             db=db, goods_id=goods.goods_id)
#     return pageInfo(total, goodss)
